package com.uls.web.controller.hdh;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.uls.hdh.domain.HdhOptions;
import com.uls.hdh.domain.HdhPolls;
import com.uls.hdh.domain.HdhUsers;
import com.uls.hdh.service.IHdhUsersService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uls.common.annotation.Log;
import com.uls.common.core.controller.BaseController;
import com.uls.common.core.domain.AjaxResult;
import com.uls.common.enums.BusinessType;
import com.uls.hdh.domain.HdhUserWeights;
import com.uls.hdh.service.IHdhUserWeightsService;
import com.uls.common.utils.poi.ExcelUtil;
import com.uls.common.core.page.TableDataInfo;

/**
 * 权重管理Controller
 * 
 * @author hdh
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/hdh/weights")
public class HdhUserWeightsController extends BaseController
{
    @Autowired
    private IHdhUserWeightsService hdhUserWeightsService;
    @Autowired
    private IHdhUsersService hdhUsersService;
    /**
     * 查询权重管理列表
     */
    @PreAuthorize("@ss.hasPermi('hdh:weights:list')")
    @GetMapping("/list")
    public TableDataInfo list(HdhUserWeights hdhUserWeights)
    {
        startPage();
        List<HdhUserWeights> list = hdhUserWeightsService.selectHdhUserWeightsList(hdhUserWeights);
        for (HdhUserWeights hdhUserWeights1:list){
            Long usersId=hdhUserWeights1.getUsersId();
            HdhUsers hdhUsers=hdhUsersService.selectHdhUsersByUsersId(usersId);
            if(hdhUsers!=null){
                hdhUserWeights1.setUsername(hdhUsers.getUsername());
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出权重管理列表
     */
    @PreAuthorize("@ss.hasPermi('hdh:weights:export')")
    @Log(title = "权重管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HdhUserWeights hdhUserWeights)
    {
        List<HdhUserWeights> list = hdhUserWeightsService.selectHdhUserWeightsList(hdhUserWeights);
        ExcelUtil<HdhUserWeights> util = new ExcelUtil<HdhUserWeights>(HdhUserWeights.class);
        util.exportExcel(response, list, "权重管理数据");
    }

    /**
     * 获取权重管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('hdh:weights:query')")
    @GetMapping(value = "/{userWeightId}")
    public AjaxResult getInfo(@PathVariable("userWeightId") Long userWeightId)
    {
        return success(hdhUserWeightsService.selectHdhUserWeightsByUserWeightId(userWeightId));
    }

    /**
     * 新增权重管理
     */
    @PreAuthorize("@ss.hasPermi('hdh:weights:add')")
    @Log(title = "权重管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HdhUserWeights hdhUserWeights)
    {
        return toAjax(hdhUserWeightsService.insertHdhUserWeights(hdhUserWeights));
    }

    /**
     * 修改权重管理
     */
    @PreAuthorize("@ss.hasPermi('hdh:weights:edit')")
    @Log(title = "权重管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HdhUserWeights hdhUserWeights)
    {
        return toAjax(hdhUserWeightsService.updateHdhUserWeights(hdhUserWeights));
    }

    /**
     * 删除权重管理
     */
    @PreAuthorize("@ss.hasPermi('hdh:weights:remove')")
    @Log(title = "权重管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userWeightIds}")
    public AjaxResult remove(@PathVariable Long[] userWeightIds)
    {
        return toAjax(hdhUserWeightsService.deleteHdhUserWeightsByUserWeightIds(userWeightIds));
    }
}
